/**
 * 
 */
package fr.esiag.isidis.pdsTeam.Test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import fr.esiag.isidis.pdsTeam.swing.Form;


import com.esiag.isidis.fi.pdsTeam.jms.producer.ActiveMQProducer;
import com.esiag.isidis.fi.pdsTeam.producer.IProducer;
import com.esiag.isidis.fi.pdsTeam.send.beans.IDLigne;
import com.esiag.isidis.fi.pdsTeam.send.beans.IDStation;
import com.esiag.isidis.fi.pdsTeam.send.beans.IDTrain;
import com.esiag.isidis.fi.pdsTeam.send.beans.Information;

/**
 * @author Admin
 *
 */
public class ProducerManager extends JFrame implements ActionListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = 124106596783655813L;
	IProducer producer;
	private Form myForm;
	public ProducerManager() {
		this.setSize(400, 400);
		this.setTitle("Producer");
		JPanel panel=new JPanel();
		myForm = new Form();
		myForm.addField("Id Train", 4);
		myForm.addField("Id Ligne", 4);
		myForm.addField("Id Station",10);
		//myForm.addField("id Station 1", 4);
		//myForm.addField("libelle Station 1", 10);
		JButton button=new JButton("send");
		button.addActionListener(this);
		panel.add(myForm);
		panel.add(button);
		this.getContentPane().add(panel);

		producer=new ActiveMQProducer(Information.class);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new ProducerManager();
	}

	public void actionPerformed(ActionEvent e) {
		
		final Information f=new Information();
		f.setTrain(new IDTrain(Integer.parseInt(myForm.getField(0))));
		f.setLigne(new IDLigne(Integer.parseInt(myForm.getField(1))));
		f.setStation(new IDStation(Integer.parseInt(myForm.getField(2))));
		
		for(int i = 0;i < 10; i++){
			new Thread(new Runnable() {
				public void run() {
					try {
						producer.send(f);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}).start();
		}
		
	}
}
